﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GTA.MONITOR.UI.GTALogCollectInterface;

namespace LanguageInfo.Common.Utilities
{
    /// <summary>
    /// 监控系统通知，可将消息发送至监控系统采集端
    /// </summary>
    public class MonitorLogHelper
    {
        private static MLogManage ml = null;
        #region 初始化LogManage对象
        /// <summary>
        /// 初始化LogManage对象
        /// </summary>
        private static MLogManage TxtLoggingObj
        {
            get
            {
                if (ml == null)
                {
                    //创建一个日志管理对象
                    ml = new MLogManage();
                    //加入文本记录器
                    ml.m_logger.AttachTraceListen(new MTextTraceListen());
                }
                return ml;
            }
        }
        #endregion

        public static void WriteLog(string CustomName, bool success, string strLevel1, string strLevel2, 
                                  string functionCode, string modeCode, string logMessage, string errorMessage, LogLevel errorType)
        {
            string projectId = "CSMAR Solution";

            var logEntry = TxtLoggingObj.CreateLog(projectId, CustomName, success ? EnumLogType.Success : EnumLogType.Fail, strLevel1, strLevel2, functionCode, modeCode, 
                logMessage, errorMessage, (EnumLogLevel)errorType);
            try
            {
                TxtLoggingObj.Wirte(logEntry);
            }
            catch (Exception ex)
            {
                Log4netHelper.Error(string.Format("发送错误信息到监控系统时出错，{0}", logMessage), ex);
            }
        }


        public enum LogLevel
        {
            NORMAL = 0,
            VERYHIGH = 1,
            HIGH = 2,
            MIDDLE = 3,
            LOW = 4,
        }
    }
}
